package com.mtbu.bean.base;
import java.util.*;
import java.text.SimpleDateFormat;
import org.json.JSONObject;
import my.json.core.JsonAble;
public abstract class SysLogBase implements JsonAble {
    private Map<String, Object> dirtyProperties = new HashMap<String, Object>();
    //ID
    private int id = 0;
    //用户名
    private String userName = "";
    //操作名称
    private String operate = "";
    //内容(执行的SQL语句等)
    private String content = "";
    //IP地址
    private String iP = "";
    //创建时间
    private Date createTime = null;
    public int getId(){
        return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    public String getUserName(){
        return this.userName;
    }
    public void setUserName(String userName){
        this.userName = userName;
        dirtyProperties.put("userName", userName);
    }
    public String getOperate(){
        return this.operate;
    }
    public void setOperate(String operate){
        this.operate = operate;
        dirtyProperties.put("operate", operate);
    }
    public String getContent(){
        return this.content;
    }
    public void setContent(String content){
        this.content = content;
        dirtyProperties.put("content", content);
    }
    public String getIP(){
        return this.iP;
    }
    public void setIP(String iP){
        this.iP = iP;
        dirtyProperties.put("iP", iP);
    }
    public Date getCreateTime(){
        return this.createTime;
    }
    public String getCreateTime_ToDateString(){
        if(createTime==null) return "";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(this.createTime);
    }
    public String getCreateTime_ToTimeString(){
        if(createTime==null) return "";
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(this.createTime);
    }
    public String getCreateTime_ToDateTimeString(){
        if(createTime==null)   return "";
        SimpleDateFormat   formatter   =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(this.createTime);
    }
    public void setCreateTime(Date createTime){
        this.createTime = createTime;
        dirtyProperties.put("createTime", createTime);
    }
    public Map<String, Object> getDirtyProperties() {
        return this.dirtyProperties;
    }
    public JSONObject toJSON() throws Exception {
        JSONObject json = new JSONObject();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        json.put("id", this.getId());
        if(userName!=null){
           json.put("userName",this.getUserName());
        }
        if(operate!=null){
           json.put("operate",this.getOperate());
        }
        if(content!=null){
           json.put("content",this.getContent());
        }
        if(iP!=null){
           json.put("iP",this.getIP());
        }
        if(createTime!=null){
            json.put("createTime",formatter.format(this.getCreateTime()));
        }
        return json;
    }
    public void fromJSON(JSONObject json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try{
            if(json.get("id") != null){
                this.setId(Integer.parseInt(json.get("id")+""));
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("userName") != null){
                this.setUserName(json.get("userName")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("operate") != null){
                this.setOperate(json.get("operate")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("content") != null){
                this.setContent(json.get("content")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("iP") != null){
                this.setIP(json.get("iP")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("createTime") != null){
                this.setCreateTime(formatter.parse(json.get("createTime")+""));
            }
        }catch(Exception ex){
        }
    }
    public void fromMap(Map<String, String> json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if(json.containsKey("id".toLowerCase())){
                this.setId(Integer.parseInt(json.get("id".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("userName".toLowerCase())){
                this.setUserName(json.get("userName".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("operate".toLowerCase())){
                this.setOperate(json.get("operate".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("content".toLowerCase())){
                this.setContent(json.get("content".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("iP".toLowerCase())){
                this.setIP(json.get("iP".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("createTime".toLowerCase())){
                this.setCreateTime(formatter.parse(json.get("createTime".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
    }
}
